<template>
    <div>
        <mHeader></mHeader>
        <div class="main-con">
            <div class="left_main">
                <leftMenu />
            </div>
            <div class="rightMain">
                <!-- 用户 -->
                <div class="list" v-for="(item, index) in list" :key="index"
                    @click="goPage('/columnIndex', item.col_id)">
                    <div class="img">
                        <div class="line1 tag" style="">
                            {{ item.act_name }}
                        </div>
                        <img :src="item.thumb" alt="">
                    </div>
                    <p class="line2"><b>【{{ item.title }}】</b>{{ item.intro }}</p>
                    <div class="bom">
                        <div class="y2">
                            <span @click.stop="goPage('/association/youping', item.user_id)"> {{ item.user_nickname
                                }}</span>
                        </div>
                        <div class="y2">
                            <i class="iconfont">&#xe61e;</i>
                            <span>{{ item.views }}</span>
                        </div>

                    </div>
                </div>
                <el-empty style="margin: 0 auto;" description="暂无内容" v-if="list.length == 0"></el-empty>


            </div>

        </div>


    </div>
</template>
<script>
import leftMenu from '@/components/leftMenu.vue';
export default {
    components: {
        leftMenu
    },
    data() {
        return {
            list: [],
            pageNum: 1,
            totalPage: 1,
            loading: false,

        };
    },
    computed: {
        path() {
            return this.$route.path
        }
    },
    mounted() {
        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件
        this.getList()

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },
    methods: {
        // 目录
        getList() {
            this.loading = true
            let params = {
                page: this.pageNum,
                id: this.id != 0 ? this.id : this.new_id
            }
            this.$api.getActivity(params).then(res => {
                if (res.data.code == 1) {
                    this.totalPage = res.data.data.last_page
                    this.list = this.list.concat(res.data.data.data);
                    this.loading = false
                }

            })
        },

        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                this.load()
            }
        },
        load() {
            console.log('触底了');
            var page = this.pageNum
            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getList()
        },
        getTabtype(t, url) {
            this.curType = t
            if (this.path != url) this.$router.push(url)

        },
        onSubmit() {
            console.log('submit!', this.form);
        },
        goPage(url, id) {
            // 另页打开
            const route = this.$router.resolve({
                path: url,
                query: { id }
            });
            window.open(route.href, '_blank');
        }
    },
}
</script>
<style lang="scss" scoped>
.main-con {
    display: flex;

    .left_main {
        margin-right: 1.04rem;
    }
}

.rightMain {
    // width: 100%;
    flex: 1;
    border-top: 0.05rem solid #E8E8E8;
    padding-top: 20px;
    display: flex;
    flex-wrap: wrap;

    .list {
        cursor: pointer;
        width: 335px;
        margin-right: 19px;
        margin-bottom: 80px;
        border-radius: 10px;
        overflow: hidden;

        &:nth-child(4n) {
            margin-right: 0;
        }

        .img {
            width: 335px;
            height: 335px;
            justify-content: center;
            align-items: center;
            display: flex;
            flex-direction: column;
            border-radius: 5px;
            overflow: hidden;
            position: relative;

            .tag {
                position: absolute;
                right: 0;
                top: 0;
                max-width: 200px;
                padding: 5px;
                background: rgba(40, 106, 195, 0.8);
                color: #ffffff;
                align-items: center;
            }

            img {
                width: 330px;
                height: 330px;
                object-fit: cover;
            }

            i {
                font-size: 100px;
                color: #999;
                border: 1px dashed #999;
                margin-bottom: 39px;
            }

            span {
                font-weight: 400;
                font-size: 24px;
                color: #666666;
            }
        }

        >p {
            font-weight: 400;
            font-size: 18px;
            color: #000000;
            margin: 24px 0 20px;
        }

        .bom {
            display: flex;
            justify-content: space-between;
            align-items: center;

            .y2 {
                padding: 0 10px;

                >div {
                    display: flex;
                    align-items: center;
                }

                i {
                    font-size: 16px;
                    margin-right: 5px;
                }

                span {
                    font-size: 14px;
                    color: #999;
                }
            }

            .collect {
                font-weight: 400;
                font-size: 16px;
                color: #999999;
            }
        }
    }
}

@media screen and (max-width:768px) {
    .left_main {
        display: none;
    }
    .main-con{
        width: 100%;
    }
    .rightMain .list {
        padding: 10px;
        width: 100%;
        height: 120px;
display: flex;
position: relative;
>p{
    font-size: 15px;
margin-left: 20px;
}
.bom{
position: absolute;
left: 160px;
bottom: 0px;
padding-right: 30px;
width: calc(100% - 160px);
.y2{
    display: flex;
    justify-content: space-between;
    align-items: center;
    span{
        font-size: 14px;
    }
    i{
        margin-right: 5px;
        font-size: 14px;
    }
}
}
        .img {
            height: 120px;
            width: 120px;

            .tag {
                position: absolute;
                right: 0;
                top: 0;
                max-width: 200px;
                padding: 5px;
                background: rgba(40, 106, 195, 0.8);
                color: #ffffff;
                align-items: center;
                font-size: 10px;
            }

            img {
                height: 120px;
                width: 120px;
            }
        }
    }
}
</style>